package com.hitown.controller.dxhd;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hitown.model.dxhd.DxhdHdzg;
import com.hitown.service.dxhd.DxhdHdzgService;
import com.hitown.util.Params;
import com.hitown.util.R;
import com.hitown.util.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Collection;

/**
 * <p>
 * 活动战果 前端控制器
 * </p>
 *
 * @author menu
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/dxhd-hdzg")
public class DxhdHdzgController {

    @Autowired
    private DxhdHdzgService dxhdHdzgService;

    @ApiOperation(value = "分页查询")
    @RequestMapping("selectPage")
    public R selectPage(@ApiIgnore @RequestBody Params<DxhdHdzg> params){
        Page<DxhdHdzg> page = new Page<>(params.getCurrent(),params.getSize());
        QueryWrapper<DxhdHdzg> wrapper =new QueryWrapper<>();
        //战果名称
        if(!StringUtils.isEmpty(params.getEntity().getZgmc())){
            wrapper.like("ZGMC",params.getEntity().getZgmc());
        }

        //活动名称
        if(!StringUtils.isEmpty(params.getEntity().getHdmc())){
            wrapper.like("HDMC",params.getEntity().getHdmc());
        }

        //活动类型
//        if(!StringUtils.isEmpty(params.getEntity().getZglx())){
//            wrapper.eq("ZGLX",params.getEntity().getZglx());
//        }

        //战果日期
        wrapper.orderByDesc("ZGSQ");
        IPage<DxhdHdzg> pageVo = dxhdHdzgService.page(page,wrapper);
        return R.ok().put("data",pageVo);

    }

    @ApiOperation(value = "根据id查询记录")
    @RequestMapping("getById")
    public R getById(@RequestParam String Id){
        DxhdHdzg result = dxhdHdzgService.getById(Id);
        return R.ok().put("data",result);

    }

    @ApiOperation(value = "保存单条记录")
    @PostMapping("save")
    public R save(@RequestBody DxhdHdzg entit){
        Boolean result = dxhdHdzgService.save(entit);
        return R.ok().put("data",result);
    }


    @ApiOperation(value = "批量保存")
    @RequestMapping("saveBatch")
    public R saveBatch(@RequestBody Collection<DxhdHdzg> entityList){
        Boolean result = dxhdHdzgService.saveBatch(entityList);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "根据 ID 选择修改")
    @RequestMapping("updateById")
    public R updateById(@RequestBody DxhdHdzg entit){
        Boolean result = dxhdHdzgService.updateById(entit);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "根据ID 批量更新")
    @RequestMapping("updateBatchById")
    public R updateBatchById(@RequestBody Collection<DxhdHdzg> entityList){
        Boolean result = dxhdHdzgService.updateBatchById(entityList);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "根据 ID 删除")
    @RequestMapping("removeById")
    public R removeById(@RequestBody DxhdHdzg entity){
        Boolean result = dxhdHdzgService.removeById(entity.getHdbh());
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "删除（根据ID 批量删除）")
    @RequestMapping("removeByIds")
    public R removeByIds(@RequestBody Collection<String> Ids){
        Boolean result = dxhdHdzgService.removeByIds(Ids);
        return R.ok().put("data",result);
    }
}

